package com.cx.mall.seckill.service.impl;


import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.cx.mall.common.entity.seckill.entity.SeckillActivity;
import com.cx.mall.seckill.mapper.SeckillActivityMapper;
import com.cx.mall.seckill.service.ISeckillActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zs
 * @since 2025-08-07
 */
@Service
public class SeckillActivityServiceImpl extends ServiceImpl<SeckillActivityMapper, SeckillActivity> implements ISeckillActivityService {

    @Override
    public List<SeckillActivity> limitList() {
        // 查询秒杀活动列表，小于结束时间，并且只查5条的
        QueryChainWrapper<SeckillActivity> queryChainWrapper = new QueryChainWrapper<>(baseMapper);
        List<SeckillActivity> list = queryChainWrapper.gt("end_time", LocalDateTime.now())
                .last("limit 5")
                .list();
        if(list.isEmpty()){
            return null;
        }
        return list;


    }

    @Override
    public List<SeckillActivity> listAllByToday() {
        QueryChainWrapper<SeckillActivity> queryChainWrapper = new QueryChainWrapper<>(baseMapper);
        queryChainWrapper.between("start_time", LocalDateTime.now(), LocalDateTime.now().plusDays(1)); // 查今天开始的秒杀活动, 今天结束的秒
        return queryChainWrapper.list();
    }
}
